import instance from './index';
import qs from 'qs';

const preUrlPath = '';
//获取用户列表-分页
const request = {
  p: ['api:user:fetch'],
  r: params => {
    return instance.get(`/user/fetchPageList`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//获取用户列表-不分页
const requestList = {
  p: ['api:user:fetch'],
  r: params => {
    return instance.get(`/user/fetchUserList`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//添加用户
const add = {
  p: ['api:user:new'],
  r: params => {
    return instance.post(`/user/new`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//获取用户信息
const info = {
  p: ['get'],
  r: params => {
    return instance.get(`/user/info`, {params}).catch(function(res){
      console.log(res)
    })
  }
};
//编辑用户
const modify = {
  p: ['api:user:modify'],
  r: params => {
    return instance.post(`/user/modify`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//删除用户
const remove = {
  p: ['api:user:delete'],
  r: params => {
    return instance.delete(`/user/del/${params.id}`)
  }
};
//关联用户-角色关联
const releUser = {
  p: ['api:role:addUserRlt'],
  r: params => {
    return instance.post(`/role/addUserRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联用户--组关联
const releUserGroup = {
  p: ['api:group:addUserRlt'],
  r: params => {
    return instance.post(`/group/addUserRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联角色-用户关联
const releRolesUser = {
  p: ['api:user:addRoleRlt'],
   r: params => {
    return instance.post(`/user/addRoleRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
};
//关联组-用户关联
const releGroupUser = {
  p: ['api:user:addGroupRlt'],
   r: params => {
    return instance.post(`/user/addGroupRlt`, qs.stringify(params),{ headers:{'Content-Type':'application/x-www-form-urlencoded'}}).catch(function(res){
      console.log(res)
    })
  }
 
};
//越权请求
const notAllowed = {
  p: ['get,/roles/notAllowed'],
  r: params => {
    return instance.get(`${preUrlPath}/GET/roles/notAllowed`, {params})
  }
}

export {
  request,
  remove,
  notAllowed,
  add,
  modify,
  info,
  requestList,
  releUser,
  releUserGroup,
  releRolesUser,
  releGroupUser
}
